package cn.edu.laud.sany.generatedata;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class SanyParaInfo
{
	protected static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	private Date startDate;
	private Date endDate;
	long startTime;
	long endTime;
	List<String> values;
	Random random;

	public SanyParaInfo()
	{
		values = new ArrayList<String>();
		random = new Random();
		startTime = 0L;
		endTime = 0L;		
	}

	public void setStart(Date date)
	{
		startDate = date;
		startTime = startDate.getTime();
	}

	public void setEnd(Date date)
	{
		endDate = date;
		endTime = endDate.getTime();
	}

	public String getRandomValues()
	{
		int size = values.size();
		if (size == 0)
		{
			return "0";
		}
		return values.get(random.nextInt(size));
	}

	public String getRandomDate()
	{
		int width1000 = (int) ((endTime - startTime) / 1000);
		if (width1000 == 0)
		{
			width1000 = 1000;
		}
		long width = random.nextInt(width1000) * 1000;
		Date date = new Date(startTime + width);
		return sdf.format(date);
	}
}
